<?php
namespace app\admin\controller;
use app\common\controller\AdminBase;
/*Ic 卡进出日志管理*/
class IcCardLog extends AdminBase{
	protected $beforeActionList = [
        'before_index'=>['only'=>'index'],
    ];
	function _initialize() {
		if(!in_array(request()->action(),array("export_excel"))){
			parent::_initialize();	
		}
    }
	/*会员卡列表*/
	function index(){
		$this->assign("shops",db("Shop")->cache("ShopsNameList",3600)->where("parent_id!=0")->order("parent_id desc,shop_name desc")->column("shop_name"));
		echo $this->fetch();
	}	
	
	/*卡列表数据*/
	function ajax_index(){
		$this->ajax($this->_ajax_index());
	}
	///////////////////////////////////////////////////////////////////////////////////
	/**
	 * 权限菜单
	 **/
	function before_index(){
		$auth_group=sp_get_auth_menu_3("10001007");
		$this->assign("menus",$auth_group);
	}
	
	/*获取卡数据*/
	private function _ajax_index(){
		$query=array(
					 'card_no'=>array("field" =>"a.card_no","operator" =>"="),
					 'name'=>array("field" =>"a.name","operator" =>"="),
					 'mobile'=>array("field" =>"a.mobile","operator" =>"="),
					 'shop_name'=>array("field" =>"b.shop_name","operator" =>"="),
					 );
		$draw=input("draw",0)+1;//请求时间		 
		$where_and=join(" and ",sp_get_param_sql(request()->isPost(),$query));
		
		if(input("behavior_status")==1){//成功
			$total=db("BehaviorLog")->alias("a")->join([['m_shop b',"a.shop_id=b.id",'LEFT']])->where($where_and)->fetchsql(FALSE)->count(1);
			$list=db("BehaviorLog")->alias("a")->field("a.id,a.shop_id,a.error_msg,a.card_no,a.in_time,a.out_time,a.name,a.mobile,a.owner_type,b.api_version,b.shop_name")->join([['m_shop b',"a.shop_id=b.id",'LEFT']])->order("a.id desc")->where($where_and)->limit($this->get_limit())->fetchsql(FALSE)->select();	
		}else{
			$total=db("BehaviorLogError")->alias("a")->join([['m_shop b',"a.shop_id=b.id",'LEFT']])->where($where_and)->fetchsql(FALSE)->count(1);
			$list=db("BehaviorLogError")->alias("a")->field("a.id,a.shop_id,a.error_msg,a.card_no,a.in_time,a.out_time,a.name,a.mobile,a.owner_type,b.api_version,b.shop_name")->join([['m_shop b',"a.shop_id=b.id",'LEFT']])->order("a.id desc")->where($where_and)->limit($this->get_limit())->fetchsql(FALSE)->select();
		}     
		
		return array('pageData'=>$list,'total'=>$total,"draw"=>$draw);
	}
	///////////////////////////////////////////////////////////////////////////////////
}